package cn.tedu.ivos.vehicle.controllor;

import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.vehicle.pojo.dto.VehicleQuery;
import cn.tedu.ivos.vehicle.pojo.dto.VehicleSaveParam;
import cn.tedu.ivos.vehicle.pojo.vo.VehicleVO;
import cn.tedu.ivos.vehicle.service.VehicleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/vehicle/")
public class VehicleController {

    @Autowired
    private VehicleService vehicleService;

    @GetMapping("select")
    public JsonResult selectVehicle(VehicleQuery vehicleQuery){
        log.debug("查询车辆数据：vehicleQuery={}",vehicleQuery);
        List<VehicleVO> list = vehicleService.selectVehicle(vehicleQuery);
        return JsonResult.ok(list);
    }
    @PostMapping("save")
    public JsonResult saveVehicle(VehicleSaveParam vehicleSaveParam){
        log.debug("新增车辆：vehicleSaveParam={}",vehicleSaveParam);
        vehicleService.saveVehicle(vehicleSaveParam);
        return JsonResult.ok();
    }

    @PostMapping("delete")
    public JsonResult deleteVehicle(Long id){
        log.debug("删除车辆：id={}",id);
        vehicleService.deleteVehicle(id);
        return JsonResult.ok();
    }
//    移除围栏绑定的车辆 将车辆禁用并将围栏绑定id设为null
    @PostMapping("unbind/{id}")
    public  JsonResult unbindVehicle(@PathVariable Long id){
        log.debug("移除围栏绑定车辆：id={}",id);
         vehicleService.unbindVehicle(id);
        return JsonResult.ok();
    }

    @PostMapping("bind/{geoId}/{id}")
    public JsonResult vehicleService(@PathVariable Long geoId, @PathVariable Long id){
        log.debug("绑定围栏车辆：geoId={}，id={}",geoId,id);
        vehicleService.vehicleService(geoId,id);
        return JsonResult.ok();
    }
}
